package com.qf.day2;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @date 2022/3/25
 * @desc
 *
 * 1.  get 和  post 的请求方式
 *
 * 2. request 代表请求对象  所有请求数据 都封装到这个对象中了，想要获取请求的数据只需要调用
 * 对应的方法即可
 *   request.getXxx()
 *
 * 3. 获取 表单的提交数据    解决乱码问题
 */
@WebServlet("/request2")
public class Request2Demo extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //设置请求参数的编码格式--对GET无效
        req.setCharacterEncoding("UTF-8");



            //获取用户名
        String username = req.getParameter("username");
        //获取密码
        String password = req.getParameter("password");
        //获取性别
        String sex = req.getParameter("sex");

        // 获取爱好
        String[] hobbies = req.getParameterValues("hobby");

        //获取日期
        String date = req.getParameter("date");

        String province = req.getParameter("province");

        String bak = req.getParameter("bak");

        System.out.println(username);
        //封装到对象

        //创建service 对象  service 对象 调用dao 对象 ，把表单提交的数据存到数据库
    }
}
